package com.eims.sls_app.ui;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.eims.sls_app.dataaccess.Lottery;
import com.eims.sls_app.dataaccess.LotteryContent;
import com.eims.sls_app.dataaccess.Schemes;
import com.eims.sls_app.dataaccess.ShowDtMatch;
import com.eims.sls_app.dataaccess.Users;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.fragment.HallFragment;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.AppTools;
import com.eims.sls_app.utils.BaseHelper;
import com.eims.sls_app.utils.LotteryUtils;
import com.eims.sls_app.view.MyToast;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import bls.juejin.cn.R;

public class PaySuccessActivity extends MyBaseActivity implements OnClickListener {
    private static final String TAG = "PaySuccessActivity";
    private Context context = PaySuccessActivity.this;
    private TextView tv_tip;// 提示
    private Button btn_select_schemeinfo;// 订单详情
    private Button btn_continue_bet;// 继续投注
    private Button btn_back_tohall;// 返回首页
    private Button btn_Luck_draw_chance;
    private String lotteryId;// 彩种id
    private int schemeId;// 方案id
    private ProgressDialog pd;

    private MyHandler myHandler;
    private MyAsynTask myAsynTask;
    private String opt, auth, info, time, imei, crc, key; // 格式化后的参数

    private long paymoney;// 花费的钱
    private String balance,uid;// 余额

    private String JinECost; // 金额消费
    private String CaiJinCost;// 彩金消费
    private String reMainCaiJin;// 剩余彩金

    private TextView tvJinECost;

    private TextView tvCaiJinCost;

    private TextView tvBalance; // 剩余金额

    private TextView tvremainCaijin;// 剩余彩金

    Schemes scheme;
    private boolean isJoin;
    /**
     * 竞彩
     */
    private List<ShowDtMatch> list_show;

    private String max_jiangjin;
    private SharedPreferences settings;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_paysuc);
        settings = this.getSharedPreferences("app_user", 0);


        if (settings.contains("uid")) {
            uid = settings.getString("uid", "0");
        }
        if(App.user!=null){
            balance=App.user.getBalance();
        }else{
            balance="--";
        }
        App.activityS.add(this);
        App.activityS1.add(this);
        findView();
        setListener();
        init();
    }



    public void findView() {
        tv_tip = (TextView) findViewById(R.id.tv_tip);
        btn_select_schemeinfo = (Button) findViewById(R.id.btn_select_schemeinfo);
        btn_continue_bet = (Button) findViewById(R.id.btn_continue_bet);
        btn_back_tohall = (Button) findViewById(R.id.btn_back_tohall);
        btn_Luck_draw_chance = (Button) findViewById(R.id.btn_Luck_draw_chance);
        btn_Luck_draw_chance.setVisibility(View.GONE);
        // 新增控件
        tvJinECost = (TextView) findViewById(R.id.tv_successJinE);
        tvCaiJinCost = (TextView) findViewById(R.id.tv_successCaiJin);
        tvBalance = (TextView) findViewById(R.id.tv_remainBalance);
        tvremainCaijin = (TextView) findViewById(R.id.tv_remainCaijin);
        scheme = new Schemes();
    }

    public void setListener() {
        btn_select_schemeinfo.setOnClickListener(this);
        btn_continue_bet.setOnClickListener(this);
        btn_back_tohall.setOnClickListener(this);
        btn_Luck_draw_chance.setOnClickListener(this);
    }

    public void init() {
        Log.i(TAG, HallFragment.listLottery + "");
        myHandler = new MyHandler();
        lotteryId = App.lottery.getLotteryID();// 获取彩种id
        schemeId = App.schemeId;// 获取方案id
        paymoney = getIntent().getLongExtra("paymoney", 0);// 获取花费钱
        JinECost = getIntent().getStringExtra("currentMoeny");
        max_jiangjin = getIntent().getStringExtra("max_jiangjin");
        // Log.e("Pay金额消费", JinECost);
        if (JinECost == null) {

            tvJinECost.setText("0.00");
        } else {

            tvJinECost.setText(JinECost);
        }

        CaiJinCost = getIntent().getStringExtra("currentHandsel");
        // Log.e("Pay彩金消费", CaiJinCost);

        if (CaiJinCost == null) {

            tvCaiJinCost.setText("0.00");

        } else {

            tvCaiJinCost.setText(CaiJinCost);
        }

        reMainCaiJin = getIntent().getStringExtra("handselMoney");
        // Log.e("Pay剩余彩金", reMainCaiJin);
        if (reMainCaiJin == null) {

            tvremainCaijin.setText("0.00");
        } else {

            tvremainCaijin.setText(reMainCaiJin);
        }

        isJoin = getIntent().getBooleanExtra("isJoin", true);// 获取是否是合买
//        balance = App.user.getBalance();// 获取方案id

        tvBalance.setText(balance);
        Spanned text = Html.fromHtml("您共花费 " + AppTools.changeStringColor("#e3393c", paymoney + "") + " 元，余额为 "
                + AppTools.changeStringColor("#e3393c", balance) + " 元");
        tv_tip.setText(text);
        /*
		 * if (Integer.parseInt(this.lotteryId)==72) { btn_back_tohall.setText("立即晒单");
		 * }
		 */

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.btn_select_schemeinfo:// 订单详情
                pd = BaseHelper.showProgress(PaySuccessActivity.this, "", "加载中...", true, false);
                Log.i(TAG, "期号" + App.lottery.getIsuseId());
                Log.i(TAG, "彩种id" + App.lottery.getLotteryID());
                if (App.qi > 1) {// 追号
                    App.lottery.setIsChase(1);
                    if (TextUtils.isEmpty(App.lottery.getLotteryID())) {
                        MyToast.getToast(context, "LotteryID为空").show();
                        return;
                    }
                    if (TextUtils.isEmpty(App.lottery.getChaseTaskID() + "")) {
                        MyToast.getToast(context, "ChaseTaskID为空").show();
                        return;
                    }
                    scheme.setIsuseID(App.lottery.getIsuseId());
                    scheme.setIsuseName(App.lottery.getIsuseName());
                    scheme.setLotteryID(App.lottery.getLotteryID());
                    scheme.setLotteryName(App.lottery.getLotteryName());
                    scheme.setLotteryName("");
                    scheme.setIsPurchasing("true");
                    scheme.setIsChase(App.lottery.getIsChase());
                    scheme.setMultiple(App.bei);
                    scheme.setMoney((double) paymoney);
                    scheme.setChaseTaskID(App.lottery.getChaseTaskID());
                    scheme.setSchemeIsOpened("False");
                    scheme.setQuashStatus(0);
                    scheme.setSchemeStatus("待出票");
                    Intent intent = new Intent(context, MyFollowLotteryInfo.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    App.scheme = scheme;
                    intent.putExtra("scheme", scheme);
                    context.startActivity(intent);
                    finish();
                } else {
                    App.lottery.setIsChase(0);
                    myAsynTask = new MyAsynTask();
                    myAsynTask.execute();
                }
                break;
            case R.id.btn_continue_bet:// 继续投注

                goToSelectLottery();
                break;
            case R.id.btn_back_tohall:// 返回首页
                App.choiceNum = true;
                backToHall();
			/*
			 * int lotteryId = Integer.parseInt(this.lotteryId); switch (lotteryId) { case
			 * 72:
			 * 
			 * for (int i = 0; i < HallFragment.listLottery.size(); i++) { if
			 * ("72".equals(HallFragment.listLottery.get(i).getLotteryID())) { //toSun();
			 * Intent intent = new Intent(PaySuccessActivity.this, SunActivity.class);
			 * intent.putExtra("schemeId", schemeId); intent.putExtra("max_jiangjin",
			 * max_jiangjin); context.startActivity(intent); } }
			 * 
			 * break; default:
			 * 
			 * break; }
			 */

                break;
            case R.id.btn_Luck_draw_chance:

			/*
			 * if (Integer.parseInt(paymoney+"")>=200) { Intent intent = new Intent(this,
			 * Luck_drawActivity.class);
			 * 
			 * startActivity(intent); }else { Toast.makeText(PaySuccessActivity.this,
			 * "最低消费200元获取一次抽奖机会", Toast.LENGTH_SHORT).show(); }
			 */

                break;
        }
    }

    private void toSun() {
        pd = BaseHelper.showProgress(PaySuccessActivity.this, "", "加载中...", true, false);
        Log.i(TAG, "期号" + App.lottery.getIsuseId());
        Log.i(TAG, "彩种id" + App.lottery.getLotteryID());
        if (App.qi > 1) {// 追号
            App.lottery.setIsChase(1);
            if (TextUtils.isEmpty(App.lottery.getLotteryID())) {
                MyToast.getToast(context, "LotteryID为空").show();
                return;
            }
            if (TextUtils.isEmpty(App.lottery.getChaseTaskID() + "")) {
                MyToast.getToast(context, "ChaseTaskID为空").show();
                return;
            }
            scheme.setIsuseID(App.lottery.getIsuseId());
            scheme.setIsuseName(App.lottery.getIsuseName());
            scheme.setLotteryID(App.lottery.getLotteryID());
            scheme.setLotteryName(App.lottery.getLotteryName());
            scheme.setLotteryName("");
            scheme.setIsPurchasing("true");
            scheme.setIsChase(App.lottery.getIsChase());
            scheme.setMultiple(App.bei);
            scheme.setMoney((double) paymoney);
            scheme.setChaseTaskID(App.lottery.getChaseTaskID());
            scheme.setSchemeIsOpened("False");
            scheme.setQuashStatus(0);
            scheme.setSchemeStatus("待出票");
            Intent intent = new Intent(PaySuccessActivity.this, SunActivity.class);
            App.scheme = scheme;
            intent.putExtra("scheme", scheme);
            context.startActivity(intent);
            finish();
        } else {
            App.lottery.setIsChase(0);
            myAsynTask = new MyAsynTask();
            myAsynTask.execute();
        }

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            backToHall();
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 异步任务
     */
    class MyAsynTask extends AsyncTask<Void, Integer, String> {

        /**
         * 在后台执行的程序
         */
        @Override
        protected String doInBackground(Void... params) {
            info = "{\"id\":" + schemeId + "}";
            opt = "15";
            Log.i("x", "投注接口 opt :" + opt);
            Log.i("x", "投注方案详情  info  " + info);

            // 加入验证后有问题,没有传key值
            key = App.key;
//			 time = RspBodyBaseBean.getTime();
            // imei = App.imei;
            // Log.i("x", "投注方案详情 key " + key);

            crc = RspBodyBaseBean.getCrc(time, imei, key, info, uid);
            // Log.i("x", "投注方案详情 crc " + crc);
            auth = RspBodyBaseBean.getAuth(crc, time, imei,uid);
            // Log.i("x", "投注方案详情=== auth " + auth);
            String[] values = {opt, auth, info};
            String result = HttpUtils.doPost(App.names, values, App.path);

            Log.i("x", "得到投注内容   " + result);

            if ("-500".equals(result))
                return result;

            if (null == result)
                return "1";

            try {

                JSONObject item = new JSONObject(result);

                if ("0".equals(item.optString("error"))) {
                    String schemeList = item.optString("schemeList");

                    JSONArray array = new JSONArray(schemeList);

                    JSONArray jsonArray2 = new JSONArray(array.toString());

                    if (jsonArray2.length() == 0)
                        return "1";
                    // 如果取消了 则停止
                    if (this.isCancelled()) {
                        Log.i("x", "取消了异步。。。。");
                        return null;
                    }
                    JSONObject items2 = jsonArray2.getJSONObject(0);
                    scheme.setId(items2.optString("id"));
                    // 设置订单编号
                    String schemeNum = items2.optString("SchemeNumber");
                    scheme.setSchemeNumber(schemeNum.equals("")
                            ? LotteryUtils.getSchemeNum(lotteryId, App.lottery.getIsuseName(), schemeId)
                            : schemeNum);
                    scheme.setIsHide(items2.optInt("isHide"));
                    scheme.setSecretMsg(items2.optString("secretMsg"));
                    scheme.setAssureMoney(items2.optDouble("assureMoney"));
                    scheme.setAssureShare(items2.optInt("assureShare"));
                    scheme.setBuyed(items2.optString("buyed"));
                    scheme.setInitiateName(items2.optString("initiateName"));
                    scheme.setInitiateUserID(items2.optString("initiateUserID"));
                    String isPurchasing = items2.optString("isPurchasing");
                    if ("".equals(isPurchasing)) {
                        isPurchasing = isJoin + "";
                    }
                    scheme.setIsPurchasing(isPurchasing);

                    // 设置订单期号
                    scheme.setIsuseID(App.lottery.getIsuseId());
                    scheme.setIsuseName(App.lottery.getIsuseName());

                    scheme.setLevel(items2.optInt("level"));
                    scheme.setLotteryID(items2.optString("lotteryID"));
                    scheme.setLotteryName(items2.optString("lotteryName"));
                    scheme.setLotteryNumber(items2.optString("lotteryNumber"));
                    scheme.setMoney(items2.optInt("money"));
                    scheme.setPlayTypeID(items2.optInt("playTypeID"));
                    scheme.setPlayTypeName(items2.optString("playTypeName"));
                    scheme.setQuashStatus(items2.optInt("quashStatus"));
                    scheme.setRecordCount(items2.optInt("recordCount"));
                    scheme.setSchedule(items2.optInt("schedule"));
                    scheme.setSchemeBonusScale(items2.optDouble("schemeBonusScale"));
                    scheme.setSchemeIsOpened(items2.optString("schemeIsOpened"));
                    scheme.setSecrecyLevel(items2.optInt("secrecyLevel"));
                    scheme.setSerialNumber(items2.optInt("serialNumber"));
                    scheme.setShare(items2.optInt("share"));
                    scheme.setShareMoney(items2.optInt("shareMoney"));
                    scheme.setSurplusShare(items2.optInt("surplusShare"));
                    scheme.setTitle(items2.optString("title"));
                    scheme.setWinMoneyNoWithTax(items2.optInt("winMoneyNoWithTax"));
                    scheme.setWinNumber(items2.optString("winNumber"));

                    // 设置订单下单时间
                    scheme.setDateTime(LotteryUtils.getSchemeTime(System.currentTimeMillis()));

                    scheme.setDescription(items2.optString("description"));
                    scheme.setIsChase(items2.optInt("isChase"));
                    scheme.setChaseTaskID(items2.optInt("chaseTaskID"));
                    // 设置倍数
                    scheme.setMultiple(App.bei);

                    scheme.setFromClient(items2.optInt("fromClient"));
                    scheme.setMyBuyMoney(item.optInt("myBuyMoney") + "");
                    scheme.setMyBuyShare(item.optInt("myBuyShare"));
                    String schemeStatus = "待出票";
                    try {
                        schemeStatus = items2.getString("schemeStatus");
                    } catch (JSONException e) {
                        // do nothing
                    }
                    scheme.setSchemeStatus(schemeStatus);

                    JSONArray array_contents = new JSONArray(items2.optString("buyContent"));
                    List<LotteryContent> contents = new ArrayList<LotteryContent>();
                    LotteryContent lotteryContent;
                    for (int k = 0; k < array_contents.length(); k++) {
                        lotteryContent = new LotteryContent();
                        try {
                            JSONArray array2 = new JSONArray(array_contents.optString(k));

                            lotteryContent.setLotteryNumber(array2.getJSONObject(0).optString("lotteryNumber"));
                            lotteryContent.setPlayType(array2.getJSONObject(0).optString("playType"));
                            lotteryContent.setSumMoney(array2.getJSONObject(0).optString("sumMoney"));
                            lotteryContent.setSumNum(array2.getJSONObject(0).optString("sumNum"));
                            contents.add(lotteryContent);
                        } catch (Exception e) {
                            JSONObject array2 = new JSONObject(array_contents.optString(k));

                            lotteryContent.setLotteryNumber(array2.optString("lotteryNumber"));
                            lotteryContent.setPlayType(array2.optString("playType"));
                            lotteryContent.setSumMoney(array2.optString("sumMoney"));
                            lotteryContent.setSumNum(array2.optString("sumNum"));
                            contents.add(lotteryContent);
                        }
                    }
                    scheme.setBuyContent(contents);

                    if (this.isCancelled()) {
                        pd.dismiss();
                        Log.i("x", "取消了异步。。。。");
                        return null;
                    }
                    return "0";
                }
            } catch (Exception e) {
                Log.i("x", "myAllLottery 错误" + e.getMessage());
            }

            return "-1";
        }

        @Override
        protected void onPostExecute(String result) {
            if (null == result)
                return;
            if ("1".equals(result)) {
                myHandler.sendEmptyMessage(-1);
            }
            myHandler.sendEmptyMessage(Integer.parseInt(result));
            super.onPostExecute(result);
        }
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();

    }

    /**
     * 进行页面刷新
     */
    @SuppressLint("HandlerLeak")
    class MyHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            if (pd != null) {
                pd.dismiss();
            }
            switch (msg.what) {
                case 0:
                    Intent intent_info;
                    if ("72".equals(scheme.getLotteryID()) || "73".equals(scheme.getLotteryID())
                            || "45".equals(scheme.getLotteryID())) {

                        intent_info = new Intent(context, MyCommonLotteryInfo_jc.class);

                        App.scheme = scheme;
                        intent_info.putExtra("scheme", scheme);
                    } else {
                        intent_info = new Intent(context, MyCommonLotteryInfo.class);
                        App.scheme = scheme;
                        intent_info.putExtra("scheme", scheme);
                    }
                    context.startActivity(intent_info);
                    break;
                default:
                    break;
                case -1:
                    MyToast.getToast(getApplicationContext(), "没有数据").show();
                    break;
                case -500:
                    MyToast.getToast(getApplicationContext(), "连接超时").show();
                    break;
                case 100:
                    // List<List<DtMatch>> list_Matchs1 = App.lottery
                    // .getList_Matchs();
                    backToHall();
                    Intent intent = new Intent(PaySuccessActivity.this, Select_jczqActivity.class);
                    PaySuccessActivity.this.startActivity(intent);
                    break;
                case 110:
                    // List<List<DtMatch>> list_Matchs2 = App.lottery
                    // .getList_Matchs();
                    // backToHall();
                    intent = new Intent(PaySuccessActivity.this, Select_jclqActivity.class);
                    intent.putExtra("from", "pay_success");
                    PaySuccessActivity.this.startActivity(intent);

                    break;
            }
            super.handleMessage(msg);
        }
    }

    /**
     * 返回首页
     */
    public void backToHall() {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        this.startActivity(intent);
        this.finish();
        for (int i = 0; i < App.activityS1.size(); i++) {
            App.activityS1.get(i).finish();
        }

    }

    /**
     * 根据彩种id跳转不同选号页面
     */
    private void goToSelectLottery() {
        Intent intent = null;
        int lotteryId = Integer.parseInt(this.lotteryId);
        switch (lotteryId) {
            case 5:// 双色球
                long currentTime_ssq = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_ssq <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                        intent = new Intent(PaySuccessActivity.this, SelectNumberActivity.class);
                    }
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 39:// 大乐透
                long currentTime_dlt = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_dlt <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                intent = new Intent(getApplicationContext(), Buy_DLT_Activit.class);
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();

                break;
            case 6:// 3D
                long currentTime_3d = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_3d <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                intent = new Intent(getApplicationContext(), SelectNumberActivityFC3D.class);
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 63:// 排列三
            case 64:// 排列五
                long currentTime = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                if (("64").equals(App.lottery.getLotteryID())) {
                    intent = new Intent(PaySuccessActivity.this, SelectNumberActivityPL5_QXC.class);
                } else {
                    intent = new Intent(PaySuccessActivity.this, SelectNumberActivityPL3.class);
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 75:// 任选九
            case 74:// 胜负彩
                long currentTime_sfc = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_sfc <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                if (App.lottery.getLotteryID().equals("74")) {
                    intent = new Intent(PaySuccessActivity.this, Buy_SFC_Activity.class);
                } else if (App.lottery.getLotteryID().equals("75")) {
                    intent = new Intent(PaySuccessActivity.this, Buy_RX9_Activit.class);
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 3:// 七星彩
                long currentTime_qxc = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_qxc <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals("3")) {
                        App.lottery = lottery;
                    }
                }
                intent = new Intent(PaySuccessActivity.this, SelectNumberActivityPL5_QXC.class);
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 13:// 七乐彩
                long currentTime_qlc = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_qlc <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }

                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals("13")) {
                        App.lottery = lottery;
                        intent = new Intent(PaySuccessActivity.this, Select_QlcActivity.class);
                        PaySuccessActivity.this.startActivity(intent);
                    }
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 62:// 十一运夺金
            case 70:// 江西11选5
            case 78:// 广东11选5
                long currentTime_11x5 = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_11x5 <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        } else {
                            App.lottery = lottery;
                        }
                    }
                }
                intent = new Intent(PaySuccessActivity.this, Select_11X5Activity.class);
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 28:// 重庆时时彩
                // backToHall();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                if ("28".equals(App.lottery.getLotteryID())) {
                    intent = new Intent(PaySuccessActivity.this, Select_SSCActivity.class);
                } else {
                    MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                    break;
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 61:// 江西时时彩
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        App.lottery = lottery;
                    }
                }
                if ("61".equals(App.lottery.getLotteryID())) {
                    intent = new Intent(PaySuccessActivity.this, Select_JXSSCActivity.class);
                    // 传递玩法
                    int JXSSCType = getIntent().getIntExtra("JXSSCType", 0);
                    Log.i(TAG, "时时彩type:" + JXSSCType);
                    intent.putExtra("JXSSCType", JXSSCType);
                    intent.putExtra("isFromPaySuccess", true);
                } else {
                    MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                    break;
                }
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;
            case 83:// 江苏快3
                // backToHall();
                long currentTime_k3 = System.currentTimeMillis();
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals(lotteryId + "")) {
                        if (lottery.getDistanceTime() - currentTime_k3 <= 0) {
                            MyToast.getToast(PaySuccessActivity.this, "该奖期已结束，请等下一期").show();
                            return;
                        }
                    }
                }
                for (Lottery lottery : HallFragment.listLottery) {
                    if (lottery.getLotteryID().equals("83")) {
                        App.lottery = lottery;
                    }
                }
                intent = new Intent(PaySuccessActivity.this, Select_k3Activity.class);
                PaySuccessActivity.this.startActivity(intent);
                PaySuccessActivity.this.finish();
                break;

            case 72:// 竞彩足球
            case 73:// 竞彩篮球
            case 45:// 北京单场
                long currentTime_jc = System.currentTimeMillis();
                for (int i = 0; i < HallFragment.listLottery.size(); i++) {
                    if ("72".equals(HallFragment.listLottery.get(i).getLotteryID())
                            || "73".equals(HallFragment.listLottery.get(i).getLotteryID())
                            || "45".equals(HallFragment.listLottery.get(i).getLotteryID())) {
//                        if (HallFragment.listLottery.get(i).getDistanceTime() - currentTime_jc <= 0) {
//                            MyToast.getToast(getApplicationContext(), "该奖期已结束，请等下一期").show();
//                            return;
//                        }
                        App.lottery = HallFragment.listLottery.get(i);
                        // MyAsynTask2 myAsynTask2 = new MyAsynTask2();
                        HallFragment.refreType = true;
                        // 对阵信息是否为空
                        if (App.lottery.getDtmatch() != null && App.lottery.getDtmatch().length() != 0) {
                            if (72 == lotteryId && "72".equals(HallFragment.listLottery.get(i).getLotteryID())) {// 竞彩足球
                                // new HallFragment()
                                // .getBallData(PaySuccessActivity.this);
                                Intent mIntent = new Intent(context, Select_jczqActivity.class);
                                mIntent.putExtra("isEmpty", true);
                                startActivity(mIntent);
                                PaySuccessActivity.this.finish();
                                break;
                            } else if (73 == lotteryId && "73".equals(HallFragment.listLottery.get(i).getLotteryID())) {// 竞彩篮球
                                // new HallFragment()
                                // .getBasketball(PaySuccessActivity.this);
                                Intent mIntent = new Intent(context, Select_jclqActivity.class);
                                mIntent.putExtra("from", "pay_success");
                                startActivity(mIntent);
                                PaySuccessActivity.this.finish();
                                break;
                            } else if (45 == lotteryId && "45".equals(HallFragment.listLottery.get(i).getLotteryID())) {// 竞彩篮球
                                new HallFragment().getBjdcData(PaySuccessActivity.this);
                                break;
                            }
                        } else {
//                            MyToast.getToast(PaySuccessActivity.this, "没有对阵信息").show();
                        }
                    }
                }
        }
    }

    @Override
    protected void onStop() {
        if (myAsynTask != null) {
            myAsynTask.cancel(true);
        }
        if (pd != null) {
            pd.dismiss();
        }
        super.onStop();
    }
}
